<?php
namespace app\data_magic\widget;

class FilterWidget extends Widget
{
    /**
     * @var array $filters 过滤条件列表
     */
    public $filters;

    /**
     * @var array $filter_actions 搜索操作列表
     */
    public $filter_actions=[];

    /**
     * 设置关联的操作，并且将其分类
     * @param array $actions 操作列表
     */
    public function setActions($actions)
    {
        foreach($actions as $action){
            if($action["data_type"]==="where"){
                $this->filter_actions[]=$action;
            }
        }
    }

    public function toArray()
    {
        $filters=[];
        foreach($this->filters as $filter){
            $filters[]=$filter->toArray();
        }
        return [
            "filters"=>$filters,
            "filter_actions"=>$this->filter_actions,
        ];
    }
}
